#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <unordered_map>
using namespace std; 

class Solution {
public:
    int minOperations(vector<int>& nums, int x) {
        int left = 0, right = 0, len = nums.size();
        int ret = 0;
        int sum = 0;
        for (auto e : nums)
        {
            sum += e;
        }
        int tmp = 0;
        int max = 0;
        while (right < len && left <= right)
        {
            tmp += nums[right];
            if (tmp > sum - x)
            {
                while (left <= right && tmp > sum - x)
                {
                    tmp -= nums[left];
                    left++;
                }
            }
            if (tmp == sum - x) max = (max > (right - left + 1)) ? max : (right - left + 1);
            right++;
        }
        if (max != 0 || sum == x)
            return len - max;
        else return -1;
    }
};


int main()
{
	return 0;
}
